<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--台站数据-->
      <el-col :span="4" :xs="24">
        <div class="head-container">
          <el-input
            v-model="equipmentName"
            placeholder="请输入台站名称"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"
          />
        </div>
        <div class="head-container">
          <el-tree
            :data="equipmentOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            default-expand-all
            @node-click="handleNodeClick"
          />
        </div>
      </el-col>
      <!--任务数据-->
      <el-col :span="20" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="任务名称" prop="taskName">
            <el-input
              v-model="queryParams.taskName"
              placeholder="请输入任务名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="任务类型" prop="type">
            <el-select v-model="queryParams.type" placeholder="请选择">
              <el-option
                v-for="dict in dict.type.task_type"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['baseinfo:collectionTask:add']"
            >新增振动任务</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAddTempTask"
              v-hasPermi="['baseinfo:collectionTask:add']"
            >新增测温任务</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['baseinfo:collectionTask:remove']"
            >删除</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading"  element-loading-text="拼命加载中..."  :data="collectionTaskList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="台站名称" align="center" prop="equipmentName" />
          <el-table-column label="任务名称" align="center" prop="taskName" />
          <el-table-column label="任务类型" align="center" prop="type" >
            <template slot-scope="scope">
              <dict-tag :options="dict.type.task_type" :value="scope.row.type"/>
            </template>
          </el-table-column>
          <el-table-column label="任务开始时间" align="center" prop="beginTime" width="180"/>
          <el-table-column label="采集时长s" align="center" prop="duration" />
          <el-table-column label="采集状态" align="center" prop="taskStatus">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.task_status" :value="scope.row.taskStatus"/>
            </template>
          </el-table-column>
          <el-table-column label="数据长度" align="center" prop="dataNumber" >
            <template slot-scope="scope">
              {{scope.row.type == '0'?scope.row.dataNumber * 1000:scope.row.dataNumber}}
            </template>
          </el-table-column>

<!--          <el-table-column label="数据文件" align="center" prop="dataFile" />-->
          <el-table-column label="数据分割" align="center" prop="inversionInterval" />
          <el-table-column label="层厚" align="center" prop="inversionSlice" />
          <el-table-column label="校正系数" align="center" prop="checkCoefficient" />
          <el-table-column label="反演状态" align="center" prop="inversionStatus" >
            <template slot-scope="scope">
              <dict-tag :options="dict.type.inversion_status" :value="scope.row.inversionStatus"/>
            </template>
          </el-table-column>
          <el-table-column label="创建人" align="center" prop="nickName" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleDataAnalysis(scope.row)"
                v-hasPermi="['baseinfo:collectionTask:edit']"

              >数据分析</el-button>
              <el-button
                v-if="scope.row.type == '0' && scope.row.taskStatus != '2'"
                size="mini"
                type="text"
                icon="el-icon-crop"
                @click="handleStop(scope.row)"
              >停止任务</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['baseinfo:collectionTask:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!-- 添加或修改任务数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="台站" prop="equipmentSn">
          <el-select v-model="form.equipmentSn"  placeholder="请选择台站">
            <el-option
              v-for="item in equipmentOptions"
              :key="item.id"
              :label="item.label"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="任务类型" prop="type">
          <el-select v-model="form.type" placeholder="请选择">
            <el-option
              v-for="dict in dict.type.task_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>-->
        <el-form-item label="任务名称" prop="taskName">
          <el-input v-model="form.taskName" placeholder="请输入任务名称" />
        </el-form-item>
        <el-form-item v-if="form.type == '0'" label="开始时间" prop="beginTime">
<!--          <el-input v-model="form.beginTime" placeholder="请选择任务开始时间" />-->
          <el-date-picker
            v-model="form.beginTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择开始日期时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="采集时长(s)" prop="duration">
          <el-input v-model="form.duration" placeholder="请输入采集时长s" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加测温任务对话框 -->
    <el-dialog :title="title" :close-on-click-modal='false' :visible.sync="openTemp" width="1200px" @close="taskClose" append-to-body>
      <el-form ref="form123" :model="form" :rules="rule123" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="台站" prop="equipmentSn">
              <el-select v-model="form.equipmentSn"  placeholder="请选择台站" @change="showTemp($event)">
                <el-option
                  v-for="item in equipmentOptions"
                  :key="item.id"
                  :label="item.label"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="当前温度">
              <el-input  :value="equipmentTemp" placeholder="当前温度" readonly/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="任务名称" prop="taskName">
              <el-input v-model="form.taskName" placeholder="请输入任务名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-col :span="24">
          <div class="chart-wrapper">
            <temp-line-chart :chart-data="tempChart"/>
          </div>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="success" @click="submitForm1">开 始</el-button>
        <el-button type="primary" @click="startHeat">开始加热</el-button>
        <el-button type="primary" @click="stopHeat">停止加热</el-button>
        <el-button type="danger" @click="cancel1">停 止</el-button>
      </div>
    </el-dialog>


    <!-- 震动数据分析对话框 -->
    <el-dialog :title="title" v-if="analysis" :visible.sync="analysis" width="800px" append-to-body  :showClose="false" >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="台站名称:" >
              {{form.equipmentName}}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="任务名称" >
              {{form.taskName}}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="数据长度" >
              {{form.dataNumber * 1000}}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-tabs v-model="activeName" >
              <el-tab-pane label="数据反演" name="0">
                <el-row v-if="activeName == 0">
                  <el-col :span="24">
                    <div class="chart-wrapper">
                      <line-chart :chart-data="form.dataList" :start="form.startData" :end="form.endData" key="key1" @receive="receive" @chartReset="chartReset" />
                    </div>
                  </el-col>
                  <el-col :span="20">
                    <el-form-item label="选择数据" label-width="80px">
                      <el-row >
                        <el-col :span="12">
                          <el-form-item label="开始" label-width="60px" prop="startData">
                            <el-input v-model="form.startData" placeholder="" />
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item label="结束" label-width="60px" prop="endData" >
                            <el-input v-model="form.endData"   placeholder="" />
                          </el-form-item>
                        </el-col>
                      </el-row>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="共" label-width="50px">
                      {{ form.endData - form.startData +1 }}
                    </el-form-item>
                  </el-col>
                  <el-col :span="9">
                    <el-form-item  label="数据分割" label-width="80px"  prop="taskName">
                      <el-input v-model="form.inversionInterval" style="width:94%;margin: 0px 30% 0 18%;" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="9">
                    <el-form-item  style="width:94%;margin-left:11%" label="层厚" prop="inversionSlice">
                      <el-input v-model="form.inversionSlice" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="6">
                    <span :style="'width: 26px;height: 26px;margin-left: 16%;margin-top:4%;border-radius: 50%;display: inline-block;background-color:'+(inversionStatus == 0?'green':'orange') "></span>
                    <el-button style="margin-left: 15%;vertical-align: top"  :disabled="inversionStatus != 0" type="primary" @click="inversionTask" >谱比/反演</el-button>
                  </el-col>

                  <el-col :span="24" v-if="form.hvData">
                    <div class="chart-wrapper">
                      <line-chart-one :chart-data="form.hvData"  />
                    </div>
                  </el-col>
                  <el-col>
                    <el-button
                      v-if="form.inversionStatus == '2'"
                      type="warning"
                      plain
                      icon="el-icon-download"
                      size="mini"
                      @click="handleExport"
                    >导出数据</el-button>
                  </el-col>
                  <el-col :span="24" v-if="inversionStatus == form.id">
                    <div style="text-align: center">
                      <img style="height: 40px" src="../../../assets/img/loading.gif"><div style="display: inline-block;height: 40px;line-height: 40px;vertical-align: top;margin-top: 5px">反演中...</div>
                    </div>
                  </el-col>
                  <el-col :span="24" v-if="inversionStatus==0 && form.inversionStatus == '2'">
                    <div style="height: 250px;">
                      <div style="display: inline-block;width: 30%;height: 100%;">
                        <img style="width: 100%;height: 100%" :src="form.dataFile+'left.jpg'">
                      </div>
                      <div style="display: inline-block;width: 70%;height: 100%;">
                        <img style="width: 100%;height: 100%" :src="form.dataFile+'right.jpg'">
                      </div>
                    </div>
                  </el-col>
                </el-row>
              </el-tab-pane>
              <el-tab-pane label="频域分析" name="1">
                <el-row v-if="activeName == 1">
                  <el-col :span="24">
                    <div class="chart-wrapper" v-if="this.activeName== 1">
                      <line-chart style="width: 100%" :chart-data="form.dataList" :start="form.analyseStart" :end="form.analyseEnd"  key="key1" @receive="receive" @chartReset="chartReset" />
                    </div>
                  </el-col>
                  <el-col :span="20">
                    <el-form-item label="选择数据" label-width="80px" >
                      <el-row >
                        <el-col :span="12">
                          <el-form-item label="开始" label-width="60px" prop="analyseStart">
                            <el-input v-model="form.analyseStart" placeholder="" />
                          </el-form-item>
                        </el-col>
                        <el-col :span="12">
                          <el-form-item label="结束" label-width="60px" prop="analyseEnd" >
                            <el-input v-model="form.analyseEnd"   placeholder="" />
                          </el-form-item>
                        </el-col>
                      </el-row>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="共" label-width="50px">
                      {{ form.analyseEnd - form.analyseStart +1 }}
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <div style="width: 100%;text-align: right">
                      <el-button style="margin-left: 15%;vertical-align: top" type="primary" @click="handleAnalyse" >计算</el-button>
                    </div>
                  </el-col>
                  <div v-if="activeer1" style="text-align: center">
                 <img style="height: 40px" src="../../../assets/img/loading.gif"><div style="display: inline-block;height: 40px;line-height: 40px;vertical-align: top;margin-top: 5px"> 正在计算数据中,请稍后...</div>
                 </div>

                  <el-col v-if="form.analyseStatus == '1'">
                    <div style="height: 250px;" class="itemBox">
                      <div class="itemPin">
                        <div class="itemPin-title">频谱图X</div>
                        <img style="width: 100%;height: 100%" :src="baseURL+form.dataFile+'xComputePlot.jpg'">
                      </div>
                      <div class="itemPin">
                        <div class="itemPin-title">频谱图Y</div>
                        <img style="width: 100%;height: 100%" :src="baseURL+form.dataFile+'yComputePlot.jpg'">
                      </div>
                      <div class="itemPin">
                        <div class="itemPin-title">频谱图Z</div>
                        <img style="width: 100%;height: 100%" :src="baseURL+form.dataFile+'zComputePlot.jpg'">
                      </div>
                    </div>
                  </el-col>


                </el-row>
              </el-tab-pane>
            </el-tabs>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog v-if="analysis1" :title="title" :visible.sync="analysis1" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="台站名称:" >
              {{form.equipmentName}}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="任务名称">
              {{form.taskName}}
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="数据长度" >
              {{form.dataNumber}}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <div class="chart-wrapper">
              <line-chart-one1 :chart-data="form.temperatureDataList" :start="form.startData" :end="form.endData" @receive="receive" @chartReset="chartReset" />
            </div>
          </el-col>
          <el-col :span="20">
            <el-form-item label="选择数据" label-width="120px">
              <el-row >
                <el-col :span="12">
                  <el-form-item label="开始" label-width="60px" prop="startData">
                    <el-input v-model="form.startData" placeholder="" />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item label="结束" label-width="60px" prop="endData" >
                    <el-input v-model="form.endData"   placeholder="" />
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="共" label-width="50px" >
              {{ form.endData - form.startData +1 }}
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item   label="校正系数:"  prop="checkCoefficient" >
              <el-input  style="margin-left:10%" v-model="form.checkCoefficient"  />
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-form-item  style="margin-left:35%;width:100%" label="对比导热系数:" prop="comHeatConductivity">
              <el-input   v-model="form.comHeatConductivity"  />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button style="margin-left: 125px;vertical-align: top"   type="primary" @click="heatConduction" >计算</el-button>
          </el-col>
          <el-col :span="12">
            <el-form-item  label="线热源法:">
            </el-form-item>
            <el-form-item  label="导热系数:" style="margin-left: 40px;" prop="heatConductivity1">
              {{form.heatConductivity1}}
            </el-form-item>
            <el-form-item  label="比热容:" style="margin-left: 40px;" prop="specificHeatCapacity">
              {{form.specificHeatCapacity}}
            </el-form-item>
            <el-form-item  label="热扩散系数:" style="margin-left: 40px;" prop="thermalDiffusionCoefficient">
              {{form.thermalDiffusionCoefficient}}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item  label="热比较法:">
            </el-form-item>
            <el-form-item  label="导热系数:" style="margin-left: 40px;" prop="heatConductivity2">
              {{form.heatConductivity2}}
            </el-form-item>
            <el-form-item  label="比热容:" style="margin-left: 40px;" prop="specificHeatCapacity">
              {{form.specificHeatCapacity2}}
            </el-form-item>
            <el-form-item  label="热扩散系数:" style="margin-left: 40px;" prop="thermalDiffusionCoefficient2">
              {{form.thermalDiffusionCoefficient2}}
            </el-form-item>
          </el-col>
          <el-col>
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              @click="handleTempExport"
            >导出数据</el-button>
          </el-col>
        </el-row>
      </el-form>

<!--      <p style="margin-top: 10px;height: 30px;line-height: 30px; ">热扩散系数:{{thermalDiffusionCoefficient}}</p>

      <p style="margin-top: 10px;height: 30px;line-height: 30px; ">比热容:{{specificHeatCapacity}}</p>-->

      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  listCollectionTask,
  getCollectionTask,
  delCollectionTask,
  addCollectionTask,
  updateCollectionTask,
  Export,
  TempExport, stopTask
} from "@/api/baseinfo/collectionTask";
import {equipmentList} from "../../../api/baseinfo/equipment";
import LineChartOne from "../../dashboard/LineChartOne";
import LineChartOne1 from "../../dashboard/LineChartOne1";
import LineChart from "../../dashboard/LineChart";
import TempLineChart from "../../dashboard/TempLineChart";
import {getInversionStatus, heatConduction, heatConductionByCompare,inversionTask,checkTempById,findTempData,startHeat,stopHeat,stopGetTemp,analyse} from "../../../api/baseinfo/collectionTask";
const baseURL = process.env.VUE_APP_BASE_API
export default {
  name: "CollectionTask",
  dicts: ['task_status', 'inversion_status', 'task_type'],
  components: {
    LineChartOne,
    LineChartOne1,
    LineChart,
    TempLineChart
  },
  data() {
    return {
      activeer1:false,
      baseURL,
      activeName:0,
      heat:false,
      timer1: null,
      tempChart: [[],[]],
      taskId: 0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 任务数据表格数据
      collectionTaskList: [],
      // 弹出层标题
      title: "",
      // 设备列表
      equipmentOptions: undefined,
      // 部门名称
      equipmentName: undefined,
      // 是否显示弹出层
      open: false,
      openTemp: false,
      analysis: false,
      analysis1: false,
      equipmentTemp: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        equipmentSn: null,
        taskName: null,
        type :null
      },
      //记录原始值 重置时使用
      start:null,
      end:null,
      analyseStart:null,
      analyseEnd:null,
      // 表单参数
      form: {},
      //反演中的任务
      inversionStatus: 0,
      //当前任务反演中
      inversioning: false,
      timer: null,
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 表单校验
      rules: {
        equipmentSn: [
          { required: true, message: "设备不能为空", trigger: "change" }
        ],
        taskName: [
          { required: true, message: "任务名称不能为空", trigger: "blur" }
        ],
        beginTime: [
          { required: true, message: "开始时间不能为空", trigger: "change" }
        ],
        checkCoefficient:[
          { required: true, message: "校正系数不能为空", trigger: "blur" }
        ],
        inversionSlice:[
          { required: true, message: "层厚不能为空", trigger: "blur" }
        ],
        comHeatConductivity:[
          { required: true, message: "对比导热系数不能为空", trigger: "blur" }
        ],
        duration: [
          { required: true, message: "采集时长不能为空", trigger: "blur" },
          { required: true,pattern:/^[+]{0,1}(\d+)$/,message: '采集时长必须为正整数', trigger: 'blur' }
        ],
        startData: [
          { required: true, message: "开始数据不能为空", trigger: "blur" },
          { required: true,pattern:/^[+]{0,1}(\d+)$/,message: '开始数据必须为正整数', trigger: 'blur' }
        ],
        endData: [
          { required: true, message: "结束数据不能为空", trigger: "blur" },
          { required: true,pattern:/^[+]{0,1}(\d+)$/,message: '结束数据必须为正整数', trigger: 'blur' }
        ],
        analyseStart: [
          { required: true, message: "开始数据不能为空", trigger: "blur" },
          { required: true,pattern:/^[+]{0,1}(\d+)$/,message: '开始数据必须为正整数', trigger: 'blur' }
        ],
        analyseEnd: [
          { required: true, message: "结束数据不能为空", trigger: "blur" },
          { required: true,pattern:/^[+]{0,1}(\d+)$/,message: '结束数据必须为正整数', trigger: 'blur' }
        ],
      },
      rule123:{
        equipmentSn: [
          { required: true, message: "设备不能为空", trigger: "change" }
        ],
        taskName: [
          { required: true, message: "任务名称不能为空", trigger: "blur" }
        ]
     },
      //导热系数
      heatConductivity: null,
      comHeatConductivity: 0.219761872718422,
      thermalDiffusionCoefficient: null,
      specificHeatCapacity: null,
      thermalDiffusionCoefficient2: null,
      specificHeatCapacity2: null
    };
  },
  watch: {
    // 根据名称筛选部门树
    equipmentName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getEquipmentList();
    this.getList();
  },
  methods: {
    /** 查询任务数据列表 */
    getList() {
      this.loading = true;
      listCollectionTask(this.queryParams).then(response => {
        this.collectionTaskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleInversionStatus() {
      this.timer = setInterval(this.statusTimer, 1000)
    },
    statusTimer() {
      getInversionStatus().then(res => {
        this.inversionStatus = res.data;
        if (this.inversionStatus == this.form.id) {
          this.inversioning = true;
        }
        if (this.inversionStatus == 0 && this.inversioning) {
          //更新任务信息
          getCollectionTask(this.form.id).then(response => {
            response.data.thermalDiffusionCoefficient=this.toNonExponential(response.data.thermalDiffusionCoefficient);
            response.data.thermalDiffusionCoefficient2=this.toNonExponential(response.data.thermalDiffusionCoefficient2);
            this.form = response.data;
            this.inversioning = false;
            this.getList();
          });
        }
      })
    },
    //接收echart数据选择
    receive(start, end) {
      if(this.activeName == 0){
        this.form.startData = start
        this.form.endData = end;
      }else if(this.activeName == 1){
        this.form.analyseStart = start;
        this.form.analyseEnd = end;
      }



    },
    //计算频域
    handleAnalyse(){
      //校验
      this.activeer1=true
      this.$refs["form"].validate(valid => {
          if (valid) {
            this.form.analyseStatus = '0';
            analyse(this.form).then(res => {
              console.log('响应',res);
              this.$modal.msgSuccess("计算完成");
              this.activeer1=false
              this.form.dataFile=res.data.dataFile;
              this.form.analyseStatus = '1';
            })
          }
      })

    },
    chartReset() {
      if(this.activeName == 0){
         this.form.startData =this.start;
        this.form.endData = this.end ;
      }else if(this.activeName == 1){
         this.form.analyseStart =this.analyseStart
         this.form.analyseEnd =this.analyseEnd
      }

    },
    /** 查询权限下的台站列表 */
    getEquipmentList() {
      equipmentList({equipmentType:'1'}).then(response => {
        this.equipmentOptions = response.data;
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.equipmentSn = data.id;
      this.handleQuery();
    },
    // 取消按钮
    cancel() {
      this.activeer1=false;
      this.open = false;
      this.openTemp = false;
      this.analysis = false;
      this.analysis1 = false;
      this.taskId = 0;
      this.reset();
      if (this.inversionStatus != 0) {
        this.getList();
      }
      if (this.timer) {
        clearInterval(this.timer);
      }
      if (this.timer1) {
        clearInterval(this.timer1);
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        equipmentSn: null,
        taskName: null,
        beginTime: null,
        duration: null,
        dataFile: null,
        inversionStatus: "0",
        inversionInterval: null,
        inversionSlice: null,
        createUser: null,
        type: null,
        logDataList: null,
        temperatureDataList: null,
      };
      this.start = null
      this.end = null
      this.analyseEnd = null
      this.analyseStart = null
      this.resetForm("form");
      this.queryParams.equipmentSn = null;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form.type ='0'
      this.open = true;
      this.title = "添加振动任务";
    },
    handleAddTempTask() {
      this.reset();
      this.form.type ='1'
      this.openTemp = true;
      this.title = "添加测温任务";
    },
    /** 修改按钮操作 */
    handleDataAnalysis(row) {
      this.loading = true;

      this.reset();
      const id = row.id || this.ids
      getCollectionTask(id).then(response => {
        response.data.thermalDiffusionCoefficient=this.toNonExponential(response.data.thermalDiffusionCoefficient);
        response.data.thermalDiffusionCoefficient2=this.toNonExponential(response.data.thermalDiffusionCoefficient2);
        this.form = response.data;
        //保存原始数据
        this.start = this.form.startData
        this.end = this.form.endData
        this.analyseStart =this.form.analyseStart
        this.analyseEnd =this.form.analyseEnd
        if(!this.form.comHeatConductivity){
          this.form.comHeatConductivity = this.comHeatConductivity;
        }
        this.loading = false;
        this.title = "数据分析";
        if (this.form.type == '0') {
          this.analysis = true;
          //获取反演状态
         this.handleInversionStatus();
        } else if (this.form.type == '1') {
          this.analysis1 = true;
        }
      });
    },
    inversionTask() {
      //校验
      this.$refs["form"].validate(valid => {
        if (valid) {
          //开始反演
          inversionTask(this.form)
        }
      })
    },
    //热源法计算导热系数
    heatConduction() {
      //校验
      this.$refs["form"].validate(valid => {
        if (valid) {
          heatConduction(this.form).then(res => {
            if(res.code==200){
              this.$modal.msgSuccess("计算完成");
            }
            res.data.thermalDiffusionCoefficient=this.toNonExponential(res.data.thermalDiffusionCoefficient);
            res.data.thermalDiffusionCoefficient2=this.toNonExponential(res.data.thermalDiffusionCoefficient2);
            this.$set(this, "form", res.data);
          })
        }
      })

    },
    toNonExponential(num) {
      var m = num.toExponential().match(/\d(?:.(\d*))?e([+-]\d+)/);
      return num.toFixed(Math.max(0, (m[1] || '').length - m[2]));
    },
    //热比较法计算导热系数
    heatConductionByCompare() {
      //对比的导热系数
      this.form.comHeatConductivity = this.comHeatConductivity;
      heatConductionByCompare(this.form).then(res => {
        //导热系数
        this.heatConductivity = res.heatConductivity;
        //热扩散系数
        this.thermalDiffusionCoefficient = null;
        //比热容
        this.specificHeatCapacity = null;
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCollectionTask(this.form).then(response => {
              this.open = false;
              this.getList();
            });
          } else {
            this.form.type = '0'
            addCollectionTask(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    submitForm1() {
      this.$refs["form123"].validate(valid => {
        this.form.type = '1';
        if (valid) {
          addCollectionTask(this.form).then(response => {
            this.$modal.msgSuccess("任务开始");
            this.taskId = response.data.id;
            this.timer1 = setInterval(this.tempChartdata, 1000);
            //this.open = false;
            //this.getList();
          });
        }
      });
    },
    tempChartdata() {
      findTempData(this.taskId).then(res => {
        let time = [];
        let temp = [];
        res.data.forEach((item,index )=>{
          temp.push(item.temperature)
          time.push(item.dataTimeStr)
        })
        let chartData = [time,temp]
        if(temp.length >1){
          this.equipmentTemp = temp[temp.length-1]+ "℃";
        }
        this.tempChart = chartData;
      });
    },
    startHeat(){
      if(this.taskId == 0){
        this.$modal.msgWarning("请先开始任务！");
        return;
      }
      startHeat(this.taskId).then(response => {
        this.heat = true;
      });
    },
    stopHeat(){
      if(this.taskId == 0){
        this.$modal.msgWarning("请先开始任务！");
        return;
      }
      if(!this.heat){
        this.$modal.msgWarning("请先开始加热！");
        return;
      }
      stopHeat(this.taskId).then(response => {
        this.heat = false;
      });
    },
    cancel1(){
      if(this.taskId == 0){
        this.$modal.msgWarning("请先开始任务！");
        return;
      }
      if(this.timer1){
        clearInterval(this.timer1);
      }
      stopGetTemp(this.taskId).then(response => {
        this.heat = false;
        this.getList();
        this.cancel();
      });
      this.tempChart=[[],[]];
      this.taskId = 0;
    },
    taskClose(){
      if(this.taskId != 0){
        this.cancel1()
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除任务数据编号为"' + ids + '"的数据项？').then(function () {
        return delCollectionTask(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      Export(this.form.id).then(response => {
        if (response.data == null) {
          this.$modal.msgSuccess("数据文件不存在，请先反演");
          return;
        }
        var a = document.createElement("a");
        a.href = response.data;
        a.style.display = "none";
        a.click();
        URL.revokeObjectURL(a.href);
      });
    },
    handleStop(row){
      this.$modal.confirm('是否确认停止"' + row.taskName + '"任务？').then(function () {
        return stopTask(row);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("任务停止成功");
      }).catch(() => {
      });
    },
    //导出温度数据
    handleTempExport(){
      TempExport(this.form.id).then(response => {
        if (response.data == null) {
          this.$modal.msgSuccess("数据文件不存在，请先反演");
          return;
        }
        var a = document.createElement("a");
        a.href = response.data;
        a.style.display = "none";
        a.click();
        URL.revokeObjectURL(a.href);
      });
    },
    showTemp(event) {
      checkTempById(event).then(response => {
        if (response.data == null) {
          this.equipmentTemp = "-℃";
          return;
        }
        this.equipmentTemp = response.data.temperature + "℃";
      })
    }
  },
  beforeDestroy() {
    if(this.timer){
      clearInterval(this.timer);
    }
    if(this.timer1){
      clearInterval(this.timer1);
    }
    if(this.taskId != 0){
      this.cancel1();
    }
  }
};
</script>
<style>
.itemBox{
  display: flex;
  justify-content: space-between;

}
.itemPin{
    display: flex;
		flex-direction: column;
		justify-content:space-between;
}
.itemPin-title{
  font-size: 14px;
  text-align: center;
  color: #333;
  
}

</style>
